package com.firewolf.springboot.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.firewolf.springboot.entities.Department;
import com.firewolf.springboot.service.DepartmentService;

@RestController
@RequestMapping("/dept")
public class DeptController {
	
	@Autowired
	private DepartmentService deptService;
	
	@RequestMapping("/addData")
	public String addData(){
		List<Department> dList = new ArrayList<>();
		dList.add(new Department("开发部", "开发各种产品", "刘兴"));
		dList.add(new Department("测试部", "测试各种产品", "智慧"));
		dList.add(new Department("运维部", "部署各种产品", "广斌"));
		deptService.addData(dList);
		return "success";
	}
	
	@RequestMapping("/find/{id}")
	@ResponseBody
	public Department findDept(@PathVariable("id") Integer id){
		return deptService.findById(id);
	}
	
	@RequestMapping("/remove/{id}")
	public String removeById(@PathVariable("id") Integer id){
		deptService.remove(id);
		return "remove success";
	}
	
	@RequestMapping("/clearAll")
	public String clearAll(){
		deptService.clearCache();
		return "clear success";
	}
	
}
